package hao.bk.royalmap;

import hao.bk.searchMap.SearchMapGeneralLayout;
import hao.bk.sql.bo.Location;

import java.util.ArrayList;
import java.util.List;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SearchFasterAdapter extends ArrayAdapter<Location> {
	
	private RoyalMapActivity context;
	private ArrayList<Location> locationList;
	
	public SearchFasterAdapter(RoyalMapActivity context, int resource,
			ArrayList<Location> locationList) {
		super(context, resource, locationList);
		this.context = context;
		this.locationList = locationList;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final Location rowItem = getItem(position);
		ViewHolder holder = null;
		LayoutInflater mInflater = context.getLayoutInflater();
		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.search_faster_list_item, null);
			holder = new ViewHolder();
			
			holder.locationName = (TextView) convertView
					.findViewById(R.id.search_faster_name);
			holder.searchFasterFloor = (TextView) convertView
					.findViewById(R.id.search_faster_floor);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		
		holder.locationName.setText(rowItem.getName());
		holder.locationName
				.setTypeface(RoyalMapActivity.fontSegoeB);
		String floor = rowItem.getAddress().substring(0, 2);// cắt chuỗi
		holder.searchFasterFloor.setText(floor+"");
		holder.searchFasterFloor.setTypeface(RoyalMapActivity.fontSegoeB);

		// Thiết lập chiều cao của từng item
		AbsListView.LayoutParams param = new AbsListView.LayoutParams(
				LayoutParams.MATCH_PARENT, 55);
		convertView.setLayoutParams(param);
		return convertView;
	}

	@Override
	public Location getItem(int position) {
		return locationList.get(position);
	}

	@Override
	public int getCount() {
		return locationList.size();
	}


	/* private view holder class */
	private class ViewHolder {
		private TextView locationName;
		private TextView searchFasterFloor;

	}

}
